﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using HAUtil;
using HAMath;


using HA.ModFlow.Infrastructure;

namespace HA.ModFlow.Domain.DomainLayer
{

    [Serializable]
    /// <summary>
    /// 用于表示三维化的网格数据
    /// </summary>
    public class GridData
    {
        protected GridData(int nrows, int ncols, int nlayers, double[] rowCoords, double[] colCoords, double[, ,] points, double orgX, double orgY, double orgZ, double rotate)
        {
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="config"></param>
        public GridData(GridConfig config)
        {
            this._config = config;

            //this.InitGrid(config.CellY,config.CellX,config.CellZ,config.LengthX,config.LengthY,config.LengthZ,config.OrgX,config.OrgY,config.OrgZ,config.Rotate);

            if (config.IsRefinedPointMode == false)
            {
                //正常模式

                this.InitNormalGridData(config.LengthX, config.LengthY, config.LengthZ, config.OrgX, config.OrgY, config.OrgZ, config.Rotate,
                        config.BiasX, config.BaseCellSizeX, config.LimitCellSizeX, config.CellX, config.IsUseBLX,
                        config.BiasY, config.BaseCellSizeY, config.LimitCellSizeY, config.CellY, config.IsUseBLY,
                        config.BiasZ, config.BaseCellSizeZ, config.LimitCellSizeZ, config.CellZ, config.IsUseBLZ
                        );

            }
            else
            {
                //RefinePoint模式

                this.InitRefinePointGridData(config.LengthX, config.LengthY, config.LengthZ, config.OrgX, config.OrgY, config.OrgZ, config.Rotate,
                    config.BiasZ, config.BaseCellSizeZ, config.LimitCellSizeZ, config.CellZ, config.IsUseBLZ, config.RefinePointList);

            }


            //初始化概念网格

            this._waterGrid = new WaterGrid(this);



        }

        GridConfig _config;

        public GridConfig Config
        {
            get { return _config; }
            set { _config = value; }
        }


        #region 事件模型


        [field: NonSerialized]
        public event EventHandler<GridModifiedEventArgs> GridModified;




        #endregion


        #region 概念网格部分


        //GridType _currentGridType = GridType.NormalGrid;
        ///// <summary>
        ///// 记录当前网格类型  Normal；Bisa；RefinePoint
        ///// </summary>
        //public GridType CurrentGridType
        //{
        //    get { return _currentGridType; }
        //    set { _currentGridType = value; }
        //}




        WaterGrid _waterGrid;

        public WaterGrid WaterGrid
        {
            get { return _waterGrid; }

        }


        #endregion


        #region 数据存储


        double[] _rowCoords;
        /// <summary>
        /// 
        /// </summary>
        public double[] RowCoords
        {
            get { return _rowCoords; }

        }

        double[] _colCoords;

        public double[] ColCoords
        {
            get { return _colCoords; }

        }


        double[] _layerCoords;

        public double[] LayerCoords
        {
            get { return _layerCoords; }

        }


        List<double[,]> _elevations;

        /// <summary>
        /// 网格各层高程信息
        /// 存放的是边框平面长方形单元中心的高程，而不是长方体单元中心点的高程，例如：4层网格则有有5层高程数据
        /// </summary>
        public List<double[,]> Elevations
        {
            get { return _elevations; }
            set
            {



                bool isChanged = false;
                isChanged = IsGridDataChanged.IsGridDataElevationChanged(this._elevations, value);

                if (isChanged == true)
                {
                    this._elevations = value;




                    this.AskElevationChanged();

                }


            }

        }



        /// <summary>
        /// 要求刷新高程显示
        /// </summary>
        public void AskElevationChanged()
        {

            if (GridModified != null)
            {

                GridModified(this, new GridModifiedEventArgs(this._elevations, GridModifiedType.ELEVATION));


            }

        }




        //一下是网格的地理信息系统

        double _orgX;

        public double OrgX
        {
            get { return _orgX; }
            set { _orgX = value; }
        }
        double _orgY;

        public double OrgY
        {
            get { return _orgY; }
            set { _orgY = value; }
        }
        double _orgZ;

        public double OrgZ
        {
            get { return _orgZ; }
            set { _orgZ = value; }
        }


        double _rotationZ;

        /// <summary>
        /// 表现用的选择角度
        /// </summary>
        public double RotationZ
        {
            get { return _rotationZ; }
            set { _rotationZ = value; }
        }

        #endregion


        #region 辅助功能函数



        /// <summary>
        /// 因为涉及到单元格和边框等概念容易混淆，故做一下说明
        /// 体单元格：长方体；层顶部高程：长方体（体单元格）上表面；面单元格：长方体上表面或者下表面长方形。
        /// 
        /// 
        /// 
        /// 取得外围边框表现形式的网格，主要用于数据表现  
        /// 返回的点的坐标是经过了旋转平移的
        /// 操作的顺序是：先旋转XY 后平移XY
        /// 
        /// 值得商榷的是：关于旋转平移和高程插值的先后顺序的问题  
        /// 比较合理的应该是：先旋转平移再进行高程插值计算，但是旋转平移不影响点和点的相对位置，对二维插值时使用的点与点的距离无影响
        /// 
        /// 说明：各层网格分别处理，上下层高程插值不相互影响，例如：1层网格，上下两个表面分别插值计算边框点的高程，不相互影响；
        /// 无效单元不参与插值计算
        /// 
        /// 
        /// </summary>
        /// <returns></returns>
        public BoundGrid GetBoundGrid()
        {

            //边框网格信息，体单元格顶点组成的网格边框
            BoundGrid bg = new BoundGrid(this.RowsCount + 1, this.ColsCount + 1, this.LayersCount + 1);


            try
            {


                if (this._waterGrid != null)
                {
                    List<int[,]> ibound = this._waterGrid.GetIBounds();
                    if (ibound != null && ibound.Count == this._layersCount && this._layersCount + 1 == this._layerCoords.Length)
                    {

                        //上述数据应该是不为null的，此处多加入有效性判断是为了避免安全隐患

                        #region

                        //遍历边框网格的各层高程

                        for (int k = 0; k < bg.LayersCount; k++)
                        {
                            //取得层平面中心点高程
                            //注意：高程_elevations中的高程值存放的是层平面中心点的高程值，并且是经过平移了的  而_layerCoords中的坐标是在网格坐标系统下的坐标值，是未经过平移的

                            bool isRight = false;

                            //_elevations [k]中的[0,0]表示左上角点（I=0，J=0）的高程（对应于界面上输入高程值窗体的左上角的位置）所以构建点的时候需要注意XYZ的对应

                            //取得边框网格的各层面单元中心点的XYZ之信息，并保存在GetBoundGridElevation中的静态字段中
                            //返回值为bool，标志其过程是否正确
                            isRight = GetBoundGridElevation.GetPlaneCellCenterPoint(_elevations[k], this._rowCoords, this._colCoords);


                            if (isRight == false)
                            {
                                //上述过程出错了

                                System.Windows.Forms.MessageBox.Show("取得BoundGrid的过程出错！！");
                                bg = new BoundGrid(this.RowsCount + 1, this.ColsCount + 1, this.LayersCount + 1);
                                return bg;

                                //break;

                            }



                            for (int i = 0; i < bg.RowsCount; i++)//外围边框点
                            {
                                for (int j = 0; j < bg.ColumnsCount; j++)
                                {
                                    //I=0，J=0,K=0表示左上角的点，而不是坐标原点  注意://创建I=0,J=0,K=0开始的网格（左上角点开始）注意点的XYZ坐标值（左下角点方向为坐标原点）。

                                    bg.GridPoints[i, j, k] = new Point3D(this.ColCoords[j], this.RowCoords[bg.RowsCount - 1 - i], this.LayerCoords[bg.LayersCount - 1 - k]);


                                    //去的观测点的高程值      左下角为坐标原点（0,0,0） 右上角为 I J K  [0,0,0]点                


                                    //进行高程插值
                                    //第一个参数为待插值点在网格坐标系下this._colCoords的坐标，如果该点所有采样点的地方都为无效单元，则返回该值
                                    //最后两个参数为网格边框层IBound信息，例如有某一个边框点 A ，第一个IBound层信息为该点上部的单元有效性，如果该店上部没有单元格，例如第一层，则
                                    //输入下部单元的IBound信息，第二个IBound曾信息为该点下部单元的有效性，如果没有则输入上部的单元格有效性



                                    if (k == 0)
                                    {
                                        //最上面一层边框点组成的面

                                        bg.GridPoints[i, j, k].Z = GetBoundGridElevation.GetOutlinerPoint(this._layerCoords[this._layerCoords.Length - 1 - k], bg.GridPoints[i, j, k], i, j, bg.RowsCount, bg.ColumnsCount, ibound[0], ibound[0]);
                                    }
                                    else if (k == bg.LayersCount - 1)
                                    {
                                        bg.GridPoints[i, j, k].Z = GetBoundGridElevation.GetOutlinerPoint(this._layerCoords[this._layerCoords.Length - 1 - k], bg.GridPoints[i, j, k], i, j, bg.RowsCount, bg.ColumnsCount, ibound[k - 1], ibound[k - 1]);
                                    }
                                    else
                                    {
                                        bg.GridPoints[i, j, k].Z = GetBoundGridElevation.GetOutlinerPoint(this._layerCoords[this._layerCoords.Length - 1 - k], bg.GridPoints[i, j, k], i, j, bg.RowsCount, bg.ColumnsCount, ibound[k - 1], ibound[k]);
                                    }


                                    //bg.GridPoints[i, j, k].Z = GetBoundGridElevation.GetOutlinerPoint(bg.GridPoints[i, j, k], i, j, bg.RowsCount, bg.ColumnsCount);



                                    #region  //将 X Y  进行旋转和平移

                                    double x = bg.GridPoints[i, j, k].X;
                                    double y = bg.GridPoints[i, j, k].Y;

                                    HAMath.Point2D newPoint = HAMath.ComputeNew2DGridPoint.GetNewPoint2D(x, y, this._orgX, this._orgY, this._rotationZ);

                                    if (newPoint == null)
                                    {
                                        System.Windows.Forms.MessageBox.Show("取得BoundGrid的过程出错！！");
                                        bg = new BoundGrid(this.RowsCount + 1, this.ColsCount + 1, this.LayersCount + 1);
                                        return bg;

                                    }
                                    else
                                    {
                                        bg.GridPoints[i, j, k].X = newPoint.X;
                                        bg.GridPoints[i, j, k].Y = newPoint.Y;
                                    }



                                    #endregion


                                }

                            }


                        }
                        #endregion


                    }


                }
                else
                {

                    #region  waterGrid为null  ，IBound为null，为保证程序流程完整性，此时仍执行高程插值但是不再考虑IBound的影响

                    for (int k = 0; k < bg.LayersCount; k++)
                    {
                        //取得平面中心点高程
                        //注意：高程_elevations中的高程值是经过平移了的  而_layerCoords中的坐标是未经过平移的

                        bool isRight = false;

                        //_elevations [k]中的[0,0]表示左上角点（I=0，J=0）的高程（对应于界面上输入高程值窗体的左上角的位置）所以构建点的时候需要注意XYZ的对应

                        isRight = GetBoundGridElevation.GetPlaneCellCenterPoint(_elevations[k], this._rowCoords, this._colCoords);


                        if (isRight == false)
                        {
                            System.Windows.Forms.MessageBox.Show("取得BoundGrid的过程出错！！");
                            bg = new BoundGrid(this.RowsCount + 1, this.ColsCount + 1, this.LayersCount + 1);
                            return bg;

                            //break;

                        }



                        for (int i = 0; i < bg.RowsCount; i++)//外围边框点
                        {
                            for (int j = 0; j < bg.ColumnsCount; j++)
                            {
                                //I=0，J=0,K=0表示左上角的点，而不是坐标原点  注意://创建I=0,J=0,K=0开始的网格（左上角点开始）注意点的XYZ坐标值（左下角点方向为坐标原点）。

                                bg.GridPoints[i, j, k] = new Point3D(this.ColCoords[j], this.RowCoords[bg.RowsCount - 1 - i], this.LayerCoords[bg.LayersCount - 1 - k]);


                                //去的观测点的高程值      左下角为坐标原点（0,0,0） 右上角为 I J K  [0,0,0]点                

                                bg.GridPoints[i, j, k].Z = GetBoundGridElevation.GetOutlinerPoint(bg.GridPoints[i, j, k], i, j, bg.RowsCount, bg.ColumnsCount);



                                #region  //将 X Y  进行旋转和平移

                                double x = bg.GridPoints[i, j, k].X;
                                double y = bg.GridPoints[i, j, k].Y;

                                HAMath.Point2D newPoint = HAMath.ComputeNew2DGridPoint.GetNewPoint2D(x, y, this._orgX, this._orgY, this._rotationZ);

                                if (newPoint == null)
                                {
                                    System.Windows.Forms.MessageBox.Show("取得BoundGrid的过程出错！！");
                                    bg = new BoundGrid(this.RowsCount + 1, this.ColsCount + 1, this.LayersCount + 1);
                                    return bg;

                                }
                                else
                                {
                                    bg.GridPoints[i, j, k].X = newPoint.X;
                                    bg.GridPoints[i, j, k].Y = newPoint.Y;
                                }



                                #endregion


                            }

                        }


                    }
                    #endregion



                }



                return bg;

            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("取得BoundGrid的过程出错！！");
                bg = new BoundGrid(this.RowsCount + 1, this.ColsCount + 1, this.LayersCount + 1);
                return bg;
            }



        }


        /// <summary>
        /// 取得三维水头网格  
        /// 返回的点的坐标是经过了旋转平移的
        ///  操作的顺序是：先旋转XY 后平移XY
        /// </summary>
        /// <returns></returns>
        public HeadGrid GetHeadGrid()
        {


            List<Point3D> planeCenterPoint = new List<Point3D>();//存放平面中心点的坐标信息
            List<double> planeCenterElevation = new List<double>();//存放某层平面中心点的高程

            HeadGrid hg = new HeadGrid(this.RowsCount, this.ColsCount, this.LayersCount);


            try
            {

                for (int k = 0; k < hg.LayersCount; k++)//外围网格单元层(对应内网格（水头）外围边框的点数)
                {
                    //取得平面中心点高程  
                    //注意：高程_elevations中的高程值是经过平移了的  而_layerCoords中的坐标是未经过平移的

                    double row = 0, col = 0;
                    for (int i = 0; i < hg.RowsCount; i++)//row外围网格单元数(对应内网格（水头）外围边框的点数)
                    {
                        for (int j = 0; j < hg.ColumnsCount; j++)//col外围网格单元数(对应内网格（水头）外围边框的点数)
                        {
                            row = _elevations[k][i, j];
                            col = _elevations[k + 1][i, j];


                            //将 X Y  进行旋转和平移

                            double x = this.ColCoords[j] + (this.ColCoords[j + 1] - this.ColCoords[j]) / 2;


                            //这里应该是减去

                            double y = this.RowCoords[this.RowsCount - i] - ((this.RowCoords[this.RowsCount - i] - this.RowCoords[this.RowsCount - 1 - i]) / 2);




                            hg.GridHeads[i, j, k] = new Point3D(x, y, (row + col) / 2);


                            #region  //将 X Y  进行旋转和平移

                            //double x = hg.GridHeads[i, j, k].X;
                            //double y = hg.GridHeads[i, j, k].Y;

                            HAMath.Point2D newPoint = HAMath.ComputeNew2DGridPoint.GetNewPoint2D(x, y, this._orgX, this._orgY, this._rotationZ);

                            if (newPoint == null)
                            {
                                System.Windows.Forms.MessageBox.Show("取得HeadGrid的过程出错！！");
                                hg = new HeadGrid(this.RowsCount, this.ColsCount, this.LayersCount);
                                return hg;

                            }
                            else
                            {
                                hg.GridHeads[i, j, k].X = newPoint.X;
                                hg.GridHeads[i, j, k].Y = newPoint.Y;
                            }

                            #endregion


                        }

                    }

                }

                return hg;

            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("取得HeadGrid的过程出错！！");
                hg = new HeadGrid(this.RowsCount, this.ColsCount, this.LayersCount);
                return hg;


            }
        }



        /// <summary>
        /// 取得指定索引的高程坐标，这里指实际的坐标值，包含了旋转和评议等操作
        /// </summary>
        /// <param name="layerIndex"></param>
        /// <returns></returns>
        public HAMath.Point2D[,] GetElevationCoords2D()
        {
            Point2D[,] coords = new Point2D[this._rowsCount, this._colsCount];



            for (int i = 0; i < this._rowsCount; i++)//row外围网格单元数(对应内网格（水头）外围边框的点数)
            {
                for (int j = 0; j < this._colsCount; j++)//col外围网格单元数(对应内网格（水头）外围边框的点数)
                {






                    //将 X Y  进行旋转和平移

                    double x = this.ColCoords[j] + (this.ColCoords[j + 1] - this.ColCoords[j]) / 2;


                    //这里应该是减去

                    double y = this.RowCoords[this.RowsCount - i] - ((this.RowCoords[this.RowsCount - i] - this.RowCoords[this.RowsCount - 1 - i]) / 2);



                    HAMath.Point2D newPoint = HAMath.ComputeNew2DGridPoint.GetNewPoint2D(x, y, this._orgX, this._orgY, this._rotationZ);

                    coords[i, j] = newPoint;



                }
            }



            return coords;
        }


        /// <summary>
        /// 这里返回的是一个，所以不需要输入序号
        /// </summary>
        /// <returns></returns>
        public Point2D[,] GetBoundaryGrid2D()
        {
            Point2D[,] result = new Point2D[this.RowsCount + 1, this.ColsCount + 1];

            for (int i = 0; i < this.RowsCount + 1; i++)//外围边框点
            {
                for (int j = 0; j < this.ColsCount + 1; j++)
                {

                    //Point2D pt = new Point2D(this.ColCoords[j], this.RowCoords[this.RowsCount - 1 - i]);






                    double x = this.ColCoords[j];
                    double y = this.RowCoords[this.RowsCount - i];






                    HAMath.Point2D newPoint = HAMath.ComputeNew2DGridPoint.GetNewPoint2D(x, y, this._orgX, this._orgY, this._rotationZ);



                    result[i, j] = newPoint;




                }

            }


            return result;

        }


        /// <summary>
        /// 取得某个位置的索引号
        /// </summary>
        /// <param name="i"></param>
        /// <param name="j"></param>
        /// <param name="k"></param>
        /// <returns>索引号</returns>
        public int GetIndex(int i, int j, int k)
        {
            int index;
            int rowCount = this.RowsCount;
            int colCount = this.ColsCount;
            if (j == colCount)
            {
                index = rowCount * colCount * (k - 1) + i * j;
            }
            else
            {
                index = rowCount * colCount * (k - 1) + (i - 1) * colCount + j;
            }
            return index;
        }


        /// <summary>
        /// 取得指定索引号的位置信息
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public int[] GetIJK(int index)
        {
            int rowCount = this.RowsCount;
            int colCount = this.ColsCount;
            int i, j, k;
            int m = index / (rowCount * colCount);
            int n = index % (rowCount * colCount);
            if (n == 0)
            {
                k = m;
                i = rowCount;
                j = colCount;
            }
            else
            {
                k = m + 1;
                if (n % colCount == 0)
                {
                    i = n / colCount;
                    j = colCount;
                }
                else
                {
                    i = n / colCount + 1;
                    j = n % colCount;
                }
            }
            int[] location = { i, j, k };
            return location;
        }


        public CellCenterDataSet3d GetTopElevationDs()
        {

            List<double[,]> elevations = this.Elevations;

            int nrow = this.RowsCount;
            int ncol = this.ColsCount;

            int nlayer = this.LayersCount;

            List<int[,]> ibound = this.WaterGrid.GetIBounds();



            double[, ,] top = new double[nrow, ncol, nlayer];


            for (int k = 0; k < nlayer; k++)
            {
                for (int i = 0; i < nrow; i++)
                {
                    for (int j = 0; j < ncol; j++)
                    {

                        top[i, j, k] = elevations[k][i, j];





                    }
                }

            }



            CellCenterDataSet3d dsTop = new CellCenterDataSet3d(top, ibound);
            dsTop.Label = "顶部高程";


            return dsTop;

        }


        public CellCenterDataSet3d GetBotElevationDs()
        {


            List<double[,]> elevations = this.Elevations;

            int nrow = this.RowsCount;
            int ncol = this.ColsCount;

            int nlayer = this.LayersCount;

            List<int[,]> ibound = this.WaterGrid.GetIBounds();




            double[, ,] bot = new double[nrow, ncol, nlayer];


            for (int k = 0; k < nlayer; k++)
            {
                for (int i = 0; i < nrow; i++)
                {
                    for (int j = 0; j < ncol; j++)
                    {


                        bot[i, j, k] = elevations[k + 1][i, j];






                    }
                }

            }






            CellCenterDataSet3d dsBot = new CellCenterDataSet3d(bot, ibound);
            dsBot.Label = "底部高程";

            return dsBot;


        }

        protected bool IsTopElevationChanged(CellCenterDataSet3d ds)
        {
            bool p = false;
            for (int k = 0; k < this.LayersCount; k++)
            {
                for (int i = 0; i < this.RowsCount; i++)
                {
                    for (int j = 0; j < this.ColsCount; j++)
                    {
                        if (ds.Datas[i, j, k] != this.Elevations[k][i, j])
                        {
                            p = true;
                            return p;
                        }
                    }
                }
            }
            return p;
        }


        public void SetTopElevationDS(CellCenterDataSet3d ds)
        {
            bool b = this.IsTopElevationChanged(ds);
            if (b)
            {
                List<double[,]> temp = new List<double[,]>();
                if (ds.GetAllGridData(temp))
                {


                    for (int k = 0; k < temp.Count; k++)
                    {
                        this._elevations[k] = temp[k];

                    }



                    this.AskElevationChanged();











                }
            }
        }

        protected bool IsBootElevationChange(CellCenterDataSet3d ds)
        {
            bool p = false;
            for (int k = 0; k < this.LayersCount; k++)
            {
                for (int i = 0; i < this.RowsCount; i++)
                {
                    for (int j = 0; j < this.ColsCount; j++)
                    {
                        if (ds.Datas[i, j, k] != this.Elevations[k + 1][i, j])
                        {
                            p = true;
                            return p;
                        }
                    }
                }
            }
            return p;
        }

        public void SetBotElevationDS(CellCenterDataSet3d ds)
        {
            bool b = this.IsBootElevationChange(ds);
            if (b)
            {
                List<double[,]> temp = new List<double[,]>();
                if (ds.GetAllGridData(temp))
                {


                    for (int k = 0; k < temp.Count; k++)
                    {
                        this._elevations[k + 1] = temp[k];

                    }



                    this.AskElevationChanged();



                }
            }
        }




        public CellCenterDataSet3d GetIBoundDs()
        {



            int nrow = this.RowsCount;
            int ncol = this.ColsCount;

            int nlayer = this.LayersCount;

            List<int[,]> ibound = this.WaterGrid.GetIBounds();



            double[, ,] dbound = new double[nrow, ncol, nlayer];

            for (int k = 0; k < nlayer; k++)
            {
                for (int i = 0; i < nrow; i++)
                {
                    for (int j = 0; j < ncol; j++)
                    {




                        dbound[i, j, k] = (double)ibound[k][i, j];



                    }
                }

            }



            CellCenterDataSet3d dsBound = new CellCenterDataSet3d(dbound, ibound);
            dsBound.Label = "IBound边界";


            return dsBound;

        }


        public void SetIBoundDs(CellCenterDataSet3d ds)
        {

            List<double[,]> temp = new List<double[,]>();
            if (ds.GetAllGridData(temp))
            {
                ds.EffIBound.Clear();
                //List<int[,]> lisTemp = new List<int[,]>();
                for (int k = 0; k < temp.Count; k++)
                {
                    int[,] ibound = new int[temp[k].GetLength(0), temp[k].GetLength(1)];
                    for (int i = 0; i < temp[k].GetLength(0); i++)
                    {
                        for (int j = 0; j < temp[k].GetLength(1); j++)
                        {
                            ibound[i, j] = (int)temp[k][i, j];
                        }
                    }
                    ds.EffIBound.Add(ibound);
                }
                this.WaterGrid.SetIBounds(ds.EffIBound);

            }




        }




        public CellCenterDataSet3d GetIHeadDs()
        {



            int nrow = this.RowsCount;
            int ncol = this.ColsCount;

            int nlayer = this.LayersCount;

            List<int[,]> ibound = this.WaterGrid.GetIBounds();

            List<double[,]> heads = this.WaterGrid.GetInitHead();


            double[, ,] ihead = new double[nrow, ncol, nlayer];


            for (int k = 0; k < nlayer; k++)
            {
                for (int i = 0; i < nrow; i++)
                {
                    for (int j = 0; j < ncol; j++)
                    {




                        ihead[i, j, k] = heads[k][i, j];






                    }
                }

            }



            CellCenterDataSet3d dsHead = new CellCenterDataSet3d(ihead, ibound);
            dsHead.Label = "初始水头";


            return dsHead;


        }


        public void SetIHeadDs(CellCenterDataSet3d ds)
        {

            List<double[,]> temp = new List<double[,]>();
            if (ds.GetAllGridData(temp))
            {
                this.WaterGrid.SetInitHeads(temp);


            }

        }


        #endregion


        #region 公共属性


        int _rowsCount;

        /// <summary>
        /// 数据的行数（单元格）
        /// </summary>
        public int RowsCount
        {
            get { return _rowsCount; }

        }

        int _colsCount;

        /// <summary>
        /// 数据的列数（单元格）
        /// </summary>
        public int ColsCount
        {
            get { return _colsCount; }

        }


        int _layersCount;

        /// <summary>
        /// 数据的层数（单元格）
        /// </summary>
        public int LayersCount
        {
            get { return _layersCount; }

        }









        #endregion

        #region 主功能函数


        /// <summary>
        /// 更新部分高程信息,之后激活对应的事件
        /// </summary>
        /// <param name="indices"></param>
        /// <param name="topValue"></param>
        /// <param name="isTop"></param>
        public void SetPartElevation(List<int> indices, double Value, bool isTop)
        {

            bool bChanged = false;

            foreach (int item in indices)
            {

                int[] ijk = this.GetIJK(item);
                int i = ijk[0];

                int j = ijk[1];

                int k = ijk[2];



                ///判断是更新顶部高程，还是底部高程

                if (isTop)
                {

                    if (this._elevations[k - 1][i - 1, j - 1] != Value)
                    {
                        this._elevations[k - 1][i - 1, j - 1] = Value;
                        bChanged = true;
                    }


                }
                else
                {
                    if (this._elevations[k][i - 1, j - 1] != Value)
                    {

                        this._elevations[k][i - 1, j - 1] = Value;
                        bChanged = true;
                    }

                }



            }

            if (bChanged)
            {

                if (GridModified != null)
                {

                    GridModified(this, new GridModifiedEventArgs(this._elevations, GridModifiedType.ELEVATION));


                }

            }





        }







        /// <summary>
        /// 移动某个点的交点的坐标值
        /// irow 行的第一个交点，以0开始的索引
        /// </summary>
        public void MoveCoords(int iRow, int iCol, double rValue, double cValue, double originX, double originY)
        {
            if (iRow == 0)
            {
                for (int i = 1; i < this._rowCoords.Length; i++)
                {
                    this._rowCoords[i] -= rValue;

                }

            }
            else
            {
                this._rowCoords[iRow] = rValue;

            }


            if (iCol == 0)
            {
                for (int j = 1; j < this._colCoords.Length; j++)
                {
                    this._colCoords[j] -= cValue;

                }



            }
            else
            {

                this._colCoords[iCol] = cValue;

            }
            this._orgX = originX;
            this._orgY = originY;

            if (GridModified != null)
            {
                GridModified(this, new GridModifiedEventArgs(null, GridModifiedType.CROSSPOINTMOVE));

            }


        }


        //行，列 间距相关的接口

        /// <summary>
        /// 设置行的间距坐标
        /// </summary>
        /// <param name="coords">具体的坐标值</param>
        public void SetRowCoords(double[] coords)
        {
            if (coords == null)
            {
                return;

            }

            if (coords.Length != this.RowsCount + 1)
            {
                Console.WriteLine("错误的行数");
                return;

            }


            this._rowCoords = coords;

            //激活对应的事件


            if (this.GridModified != null)
            {
                GridModified(this, new GridModifiedEventArgs(this._rowCoords, GridModifiedType.ROWCOORDS));

            }




        }

        /// <summary>
        /// 设置列的间距坐标值，如10,20,30
        /// </summary>
        /// <param name="coords"></param>
        public void SetColCoords(double[] coords)
        {

            if (coords == null)
            {
                return;

            }

            if (coords.Length != this.RowsCount + 1)
            {
                Console.WriteLine("错误的行数");
                return;

            }


            this._colCoords = coords;

            //激活对应的事件




            if (this.GridModified != null)
            {
                GridModified(this, new GridModifiedEventArgs(this._colCoords, GridModifiedType.COLCOORDS));

            }


        }




        #endregion


        #region 内部方法

        /// <summary>
        /// 临时性的，用于构建普通类型玩个
        /// </summary>
        public void InitGrid(int nrows, int ncols, int nlayers, double xlength, double ylength, double zlength, double orgX, double orgY, double orgZ, double rotate)
        {
            #region 伪代码


            #endregion

            #region

            //this.CurrentGridType = GridType.NormalGrid;


            #region

            ///坐标原点信息

            this._orgX = orgX;
            this._orgY = orgY;
            this._orgZ = orgZ;

            this._rotationZ = rotate;


            _rowCoords = new double[nrows + 1];//一维数组长度为 nrows+1  边框点

            for (int i = 0; i < nrows + 1; i++)
            {
                ///需要加入原始的初始化坐标值
                ///
                //_rowCoords[i] = (ylength / nrows) * (i)+this._orgY;

                _rowCoords[i] = (ylength / nrows) * (i);

            }

            _colCoords = new double[ncols + 1];//边框点

            for (int j = 0; j < ncols + 1; j++)
            {
                //_colCoords[j] = (xlength / ncols) * (j)+this._orgX;

                _colCoords[j] = (xlength / ncols) * (j);

            }


            _layerCoords = new double[nlayers + 1];//边框点

            for (int k = 0; k < nlayers + 1; k++)
            {
                //_layerCoords[k] = (zlength / nlayers) * (k)+this._orgZ;

                _layerCoords[k] = (zlength / nlayers) * (k);

            }

            #endregion


            _elevations = new List<double[,]>();

            ///高程的网格要多一些，哈哈
            for (int k = 0; k < nlayers + 1; k++)//共有  层
            {
                double height = zlength * (nlayers - k) / nlayers + orgZ;

                double[,] ele = new double[nrows, ncols];// 每一层的平面图的四边形网格的中心点高程

                for (int i = 0; i < nrows; i++)
                {
                    for (int j = 0; j < ncols; j++)
                    {
                        ele[i, j] = height;
                    }

                }
                _elevations.Add(ele);//共有  层

            }


            ///更新网格信息


            this._rowsCount = nrows; //网格Y
            this._colsCount = ncols; //网格X


            this._layersCount = nlayers; //网格Z






            #endregion

        }
        /// <summary>
        ///  取得 RefinePoint信息   出错返回  Count=0
        /// </summary>
        /// <returns></returns>
        private List<RefinePoint> GetRefinePoint()
        {
            List<RefinePoint> refinePoint = new List<RefinePoint>();

            //if ()
            //{         
            //}





            return refinePoint;
        }


        /// <summary>
        /// 更新构建正常模式网格的参数
        /// </summary>
        private void InitNormalGridData(double xlength, double ylength, double zlength, double orgX, double orgY, double orgZ, double rotate,
            double xBias, double xBaseCellSize, double xMaxCellSize, int xNumCell, bool xUseBaseLimit,
            double yBias, double yBaseCellSize, double yMaxCellSize, int yNumCell, bool yUseBaseLimit,
            double zBias, double zBaseCellSize, double zMaxCellSize, int zNumCell, bool zUseBaseLimit)
        {

            //简单的数据有效性检验

            if (xlength <= 0 || ylength <= 0 || zlength <= 0)
            {
                return;
            }

            if (yUseBaseLimit == false && yNumCell <= 0)
            {
                System.Windows.Forms.MessageBox.Show("您设置的Y方向的单元格数目可能错误！将按照默认 10 处理！");
                yNumCell = 10;
            }
            if (xUseBaseLimit == false && xNumCell <= 0)
            {
                System.Windows.Forms.MessageBox.Show("您设置的X方向的单元格数目可能错误！将按照默认 8 处理！");
                xNumCell = 10;

            }
            if (zUseBaseLimit == false && zNumCell <= 0)
            {
                System.Windows.Forms.MessageBox.Show("您设置的Z方向的单元格数目可能错误！将按照默认 4 处理！");
                zNumCell = 4;
            }
            //需要添加 Bias 的方式
            #region

            ///坐标原点信息

            this._orgX = orgX;
            this._orgY = orgY;
            this._orgZ = orgZ;
            this._rotationZ = rotate;

            int xCellNum = xNumCell;
            int yCellNum = yNumCell;
            int zCellNum = zNumCell;



            #region 以下是计算相对于网格坐标系下的点与原点的距离（对于0的坐标）

            // X Y Z 各方向分别有两种情况

            if (yUseBaseLimit == false)
            {

                if (yBias <= 0)
                {
                    System.Windows.Forms.MessageBox.Show("您设置的YBias值小于等于0！将按照YBias=1处理！");
                    yBias = 1;
                }


                List<double> rowCoor = new List<double>();

                rowCoor = CreateGridFromBias.NoBaseLimitBiasGrid(ylength, yBias, yNumCell);

                if (rowCoor.Count >= 2)
                {
                    _rowCoords = new double[rowCoor.Count];//一维数组长度为 nrows+1  边框点

                    for (int i = 0; i < rowCoor.Count; i++)
                    {
                        _rowCoords[i] = rowCoor[i];
                    }
                }
                else
                {
                    _rowCoords = new double[yNumCell + 1];//一维数组长度为 nrows+1  边框点
                    for (int i = 0; i < yNumCell + 1; i++)
                    {
                        ///需要加入原始的初始化坐标值
                        //_rowCoords[i] = (ylength / nrows) * (i)+this._orgY;
                        _rowCoords[i] = (ylength / yNumCell) * (i);
                    }

                }

            }
            else
            {
                List<double> rowCoor = new List<double>();

                rowCoor = CreateGridFromBias.HasBaseLimitBiasGrid(ylength, yBias, yBaseCellSize, yMaxCellSize);

                if (rowCoor.Count >= 2)
                {
                    _rowCoords = new double[rowCoor.Count];//一维数组长度为 nrows+1  边框点

                    for (int i = 0; i < rowCoor.Count; i++)
                    {
                        _rowCoords[i] = rowCoor[i];
                    }

                    yCellNum = rowCoor.Count - 1;
                }
                else
                {
                    _rowCoords = new double[2];
                    _rowCoords[0] = 0.0;
                    _rowCoords[1] = 10.0;

                    yCellNum = 1;
                }


            }


            if (xUseBaseLimit == false)
            {

                if (xBias <= 0)
                {
                    System.Windows.Forms.MessageBox.Show("您设置的XBias值小于等于0！将按照XBias=1处理！");
                    xBias = 1;
                }


                List<double> colCoor = new List<double>();

                colCoor = CreateGridFromBias.NoBaseLimitBiasGrid(xlength, xBias, xNumCell);

                if (colCoor.Count >= 2)
                {
                    _colCoords = new double[colCoor.Count];//一维数组长度为 nrows+1  边框点

                    for (int i = 0; i < colCoor.Count; i++)
                    {
                        _colCoords[i] = colCoor[i];
                    }

                }
                else
                {
                    _colCoords = new double[xNumCell + 1];//边框点
                    for (int j = 0; j < xNumCell + 1; j++)
                    {
                        //_colCoords[j] = (xlength / ncols) * (j)+this._orgX;
                        _colCoords[j] = (xlength / xNumCell) * (j);
                    }
                }



            }
            else
            {
                List<double> colCoor = new List<double>();

                colCoor = CreateGridFromBias.HasBaseLimitBiasGrid(xlength, xBias, xBaseCellSize, xMaxCellSize);

                if (colCoor.Count >= 2)
                {
                    _colCoords = new double[colCoor.Count];//一维数组长度为 nrows+1  边框点

                    for (int i = 0; i < colCoor.Count; i++)
                    {
                        _colCoords[i] = colCoor[i];
                    }

                    xCellNum = colCoor.Count - 1;

                }
                else
                {
                    _colCoords = new double[2];
                    _colCoords[0] = 0.0;
                    _colCoords[1] = 10.0;

                    xCellNum = 1;
                }


            }

            if (zUseBaseLimit == false)
            {
                if (zBias <= 0)
                {
                    System.Windows.Forms.MessageBox.Show("您设置的ZBias值小于等于0！将按照ZBias=1处理！");
                    zBias = 1;
                }

                List<double> layerCoor = new List<double>();

                layerCoor = CreateGridFromBias.NoBaseLimitBiasGrid(zlength, zBias, zNumCell);

                if (layerCoor.Count >= 2)
                {
                    _layerCoords = new double[layerCoor.Count];//一维数组长度为 nrows+1  边框点

                    for (int i = 0; i < layerCoor.Count; i++)
                    {
                        _layerCoords[i] = layerCoor[i];
                    }
                }
                else
                {
                    _layerCoords = new double[zNumCell + 1];//边框点
                    for (int k = 0; k < zNumCell + 1; k++)
                    {
                        //_layerCoords[k] = (zlength / nlayers) * (k)+this._orgZ;
                        _layerCoords[k] = (zlength / zNumCell) * (k);
                    }
                }

            }
            else
            {
                List<double> layerCoor = new List<double>();

                layerCoor = CreateGridFromBias.HasBaseLimitBiasGrid(zlength, zBias, zBaseCellSize, zMaxCellSize);

                if (layerCoor.Count >= 2)
                {
                    _layerCoords = new double[layerCoor.Count];//一维数组长度为 nrows+1  边框点

                    for (int i = 0; i < layerCoor.Count; i++)
                    {
                        _layerCoords[i] = layerCoor[i];
                    }

                    zCellNum = layerCoor.Count - 1;

                }
                else
                {
                    _layerCoords = new double[2];
                    _layerCoords[0] = 0.0;
                    _layerCoords[1] = 10.0;

                    zCellNum = 1;

                }

            }


            #endregion




            #endregion

            #region  需要重新考虑  _elevations  的计算

            _elevations = new List<double[,]>();

            ///高程的网格要多一些，哈哈
            for (int k = 0; k < zCellNum + 1; k++)//共有  层
            {
                //double height = zlength * (zCellNum  - k) / zCellNum  + orgZ;
                double height = _layerCoords[zCellNum - k] + orgZ;

                double[,] ele = new double[yCellNum, xCellNum];// 每一层的平面图的四边形网格的中心点高程

                for (int i = 0; i < yCellNum; i++)
                {
                    for (int j = 0; j < xCellNum; j++)
                    {
                        ele[i, j] = height;
                    }
                }
                _elevations.Add(ele);//共有  层

            }


            ///更新网格信息


            this._rowsCount = yCellNum; //网格Y
            this._colsCount = xCellNum; //网格X


            this._layersCount = zCellNum; //网格Z






            #endregion


        }
        /// <summary>
        /// 更新构建RefinePoint模式网格的参数
        /// </summary>
        private void InitRefinePointGridData(double xlength, double ylength, double zlength, double orgX, double orgY, double orgZ, double rotate,
            double zBias, double zBaseCellSize, double zMaxCellSize, int zNumCell, bool zUseBaseLimit,
            List<RefinePoint> refinePointList)
        {


            //需要添加 Bias 的方式

            // 构建RefinePoint类型
            //构造函数中的参数还有待商榷
            //坐标原点信息

            #region

            this._orgX = orgX;
            this._orgY = orgY;
            this._orgZ = orgZ;

            this._rotationZ = rotate;


            int nRows = 1;
            int nCols = 1;
            int nLayers = 1;


            XYCoorResult xyCoor;

            xyCoor = this.GetXYCoorRefinePointGrid(orgX, orgY, xlength, ylength, rotate, refinePointList);

            nRows = xyCoor.YCoor.Count - 1;
            nCols = xyCoor.XCoor.Count - 1;

            if (zUseBaseLimit == false && zNumCell <= 0)
            {
                System.Windows.Forms.MessageBox.Show("您设置的Z方向的单元格数目可能错误！将按照默认 4 处理！");
                zNumCell = 4;
            }

            nLayers = zNumCell;//这个不确定  和是否使用Bias有关  暂时先这样

            this._rowCoords = new double[nRows + 1];
            this._colCoords = new double[nCols + 1];
            //this._layerCoords = new double[nLayers + 1];


            if (xyCoor.XCoor.Count > 1 && xyCoor.YCoor.Count > 1)
            {
                #region

                for (int i = 0; i < xyCoor.YCoor.Count; i++)
                {
                    _rowCoords[i] = xyCoor.YCoor[i];//从左向右  依次变大

                }
                for (int i = 0; i < xyCoor.XCoor.Count; i++)
                {
                    _colCoords[i] = xyCoor.XCoor[i];// 依次变小  上到下

                }

                //for (int k = 0; k < nLayers + 1; k++)
                //{
                //    _layerCoords[k] = (zlength / nLayers) * (k);

                //}

                #region

                if (zUseBaseLimit == false)
                {

                    List<double> layerCoor = new List<double>();

                    layerCoor = CreateGridFromBias.NoBaseLimitBiasGrid(zlength, zBias, zNumCell);

                    if (layerCoor.Count >= 2)
                    {
                        _layerCoords = new double[layerCoor.Count];//一维数组长度为 nrows+1  边框点

                        for (int i = 0; i < layerCoor.Count; i++)
                        {
                            _layerCoords[i] = layerCoor[i];
                        }
                    }
                    else
                    {
                        _layerCoords = new double[zNumCell + 1];//边框点
                        for (int k = 0; k < zNumCell + 1; k++)
                        {
                            //_layerCoords[k] = (zlength / nlayers) * (k)+this._orgZ;
                            _layerCoords[k] = (zlength / zNumCell) * (k);
                        }
                    }

                }
                else
                {
                    List<double> layerCoor = new List<double>();

                    layerCoor = CreateGridFromBias.HasBaseLimitBiasGrid(zlength, zBias, zBaseCellSize, zMaxCellSize);

                    if (layerCoor.Count >= 2)
                    {
                        _layerCoords = new double[layerCoor.Count];//一维数组长度为 nrows+1  边框点

                        for (int i = 0; i < layerCoor.Count; i++)
                        {
                            _layerCoords[i] = layerCoor[i];
                        }

                        nLayers = layerCoor.Count - 1;

                    }
                    else
                    {
                        _layerCoords = new double[2];
                        _layerCoords[0] = 0.0;
                        _layerCoords[1] = 10.0;

                        nLayers = 1;

                    }

                }

                _elevations = new List<double[,]>();

                ///高程的网格要多一些，哈哈
                for (int k = 0; k < nLayers + 1; k++)//共有  层
                {
                    //double height = zlength * (zCellNum  - k) / zCellNum  + orgZ;
                    double height = _layerCoords[nLayers - k] + orgZ;

                    double[,] ele = new double[nRows, nCols];// 每一层的平面图的四边形网格的中心点高程

                    for (int i = 0; i < nRows; i++)
                    {
                        for (int j = 0; j < nCols; j++)
                        {
                            ele[i, j] = height;
                        }
                    }
                    _elevations.Add(ele);//共有  层

                }


                #endregion



                ///更新网格信息


                this._rowsCount = nRows; //网格Y
                this._colsCount = nCols; //网格X


                this._layersCount = nLayers; //网格Z






                #endregion

            }
            else
            {
                #region

                if (nRows <= 1)
                {
                    this._rowCoords = new double[2];
                    _rowCoords[0] = 0;
                    _rowCoords[1] = 10;

                    nRows = 1;
                }
                if (nCols <= 1)
                {
                    this._colCoords = new double[2];
                    _colCoords[0] = 0;
                    _colCoords[1] = 10;

                    nCols = 1;
                }

                //for (int k = 0; k < nLayers + 1; k++)
                //{
                //    _layerCoords[k] = (zlength / nLayers) * (k);

                //}


                #region

                if (zUseBaseLimit == false)
                {

                    List<double> layerCoor = new List<double>();

                    layerCoor = CreateGridFromBias.NoBaseLimitBiasGrid(zlength, zBias, zNumCell);

                    if (layerCoor.Count >= 2)
                    {
                        _layerCoords = new double[layerCoor.Count];//一维数组长度为 nrows+1  边框点

                        for (int i = 0; i < layerCoor.Count; i++)
                        {
                            _layerCoords[i] = layerCoor[i];
                        }
                    }
                    else
                    {
                        _layerCoords = new double[zNumCell + 1];//边框点
                        for (int k = 0; k < zNumCell + 1; k++)
                        {
                            //_layerCoords[k] = (zlength / nlayers) * (k)+this._orgZ;
                            _layerCoords[k] = (zlength / zNumCell) * (k);
                        }
                    }

                }
                else
                {
                    List<double> layerCoor = new List<double>();

                    layerCoor = CreateGridFromBias.HasBaseLimitBiasGrid(zlength, zBias, zBaseCellSize, zMaxCellSize);

                    if (layerCoor.Count >= 2)
                    {
                        _layerCoords = new double[layerCoor.Count];//一维数组长度为 nrows+1  边框点

                        for (int i = 0; i < layerCoor.Count; i++)
                        {
                            _layerCoords[i] = layerCoor[i];
                        }

                        nLayers = layerCoor.Count - 1;

                    }
                    else
                    {
                        _layerCoords = new double[2];
                        _layerCoords[0] = 0.0;
                        _layerCoords[1] = 10.0;

                        nLayers = 1;

                    }

                }

                _elevations = new List<double[,]>();

                ///高程的网格要多一些，哈哈
                for (int k = 0; k < nLayers + 1; k++)//共有  层
                {
                    //double height = zlength * (zCellNum  - k) / zCellNum  + orgZ;
                    double height = _layerCoords[nLayers - k] + orgZ;

                    double[,] ele = new double[nRows, nCols];// 每一层的平面图的四边形网格的中心点高程

                    for (int i = 0; i < nRows; i++)
                    {
                        for (int j = 0; j < nCols; j++)
                        {
                            ele[i, j] = height;
                        }
                    }
                    _elevations.Add(ele);//共有  层

                }

                #endregion



                ///更新网格信息


                this._rowsCount = nRows; //网格Y
                this._colsCount = nCols; //网格X


                this._layersCount = nLayers; //网格Z




                #endregion

            }

            #endregion

        }




        /// <summary>
        /// 取得 RefienPoint 映射的网格的 X Y 坐标分布 出错返回   xyCoorResult 中两个 List 的Count=0
        /// </summary>
        /// <param name="orgX"></param>
        /// <param name="orgY"></param>
        /// <param name="xLen"></param>
        /// <param name="yLen"></param>
        /// <param name="rogateZ"></param>
        /// <param name="refinePoint"></param>
        /// <returns></returns>
        private XYCoorResult GetXYCoorRefinePointGrid(double orgX, double orgY, double xLen, double yLen, double rotateZ, List<RefinePoint> refinePoint)
        {

            XYCoorResult xyCoorResult = new XYCoorResult();

            #region 相关的数据有效性检验

            if (refinePoint == null)
            {
                return xyCoorResult;
            }
            if (xLen <= 0 || yLen <= 0)
            {
                return xyCoorResult;
            }

            #endregion


            //为操作的方便，  需要去掉旋转带来的使用距离时的影响，传递过来的数据都是相对于点的坐标系的
            //而这些数据中的网格数据是包含有旋转的
            //初级方案：将点的数据转换到网格坐标系（那到底是先旋转还是先平移呢？？？），计算结果是相对于
            //网格坐标系的，然后再转换到点坐标系下。

            #region 构建基本数据

            //构建网格信息  以网格坐标系为基准

            GridFrameParameter gridFrame = new GridFrameParameter();

            #region
            gridFrame.LowLeft.XCoordinate = 0.0;
            gridFrame.LowLeft.YCoordinate = 0.0;

            gridFrame.LowRight.XCoordinate = xLen;
            gridFrame.LowRight.YCoordinate = 0.0;

            gridFrame.UpLeft.XCoordinate = 0.0;
            gridFrame.UpLeft.YCoordinate = yLen;

            gridFrame.UpRight.XCoordinate = xLen;
            gridFrame.UpRight.YCoordinate = yLen;

            gridFrame.CoorChanged();

            #endregion

            //点信息  并转换到网格坐标系中
            List<RefinePoint> refinePointList = new List<RefinePoint>();

            for (int i = 0; i < refinePoint.Count; i++)
            {
                RefinePoint point = new RefinePoint();
                point = (RefinePoint)refinePoint[i].Clone();

                Point2D point2DNew;
                point2DNew = Change2DCartesianCoordinateSystem.GetPointInCS1ToCS2(point.RefinePointCoor.XCoordinate, point.RefinePointCoor.YCoordinate, orgX, orgY, rotateZ);

                if (point2DNew == null)
                {
                    return null;
                }
                else
                {
                    if (point2DNew.X < gridFrame.LowLeft.XCoordinate || point2DNew.X > gridFrame.LowRight.XCoordinate || point2DNew.Y < gridFrame.LowLeft.YCoordinate || point2DNew.Y > gridFrame.UpLeft.YCoordinate)//如果该RefinePoint点不再网格内部则不进行映射
                    {
                        continue;//点不再网格内部 不进行映射
                    }
                    else
                    {
                        point.RefinePointCoor.XCoordinate = point2DNew.X;
                        point.RefinePointCoor.YCoordinate = point2DNew.Y;

                        refinePointList.Add(point);
                    }
                }
            }

            #endregion

            //计算映射后的 XY 方向上的距离关系
            xyCoorResult = CreateGridFromRefinePoints.CreateGridRefinePoints(gridFrame, refinePointList);




            return xyCoorResult;

        }


        #endregion

    }
}
